package com.hyt.it.ogt.pj.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Param;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hyt.it.ogt.pj.model.entity.PieceScore;
import com.hyt.it.ogt.pj.model.entity.Task;
import com.hyt.it.ogt.pj.model.param.ExamExpertSettingParam;
import com.hyt.it.ogt.pj.model.vo.OptionItemVo;
import com.hyt.it.ogt.pj.model.vo.TaskNumberVo;
import com.hyt.it.ogt.pj.model.vo.TaskPieceScoreVo;
import com.hyt.it.ogt.pj.model.vo.TaskVo;

/**
 * <p>
 * 评卷任务表 Mapper 接口
 * </p>
 *
 * @author qiaozj
 * @since 2020-07-09
 */
public interface TaskMapper extends BaseMapper<Task> {

    Task selectLoadedTask(@Param("projectId") String projectId, @Param("subjectId") String subjectId, @Param("pieceCode") String pieceCode, @Param("userId") String userId);

    Task selectMarkTask(@Param("projectId") String projectId, @Param("subjectId") String subjectId, @Param("pieceCode") String pieceCode);

    void updateStatus(Task task);

    List<Task> selectUnMarkTask(@Param("projectId") String projectId, @Param("subjectId") String subjectId, @Param("pieceId") String pieceId);

    List<Task> getStudentSubjectTask(@Param("projectId") String projectId, @Param("subjectId") String subjectId, @Param("admissionNum") String admissionNum);

    List<Task> getStudentSubjectTaskByAdmissionNums(@Param("projectId") String projectId, @Param("subjectId") String subjectId, @Param("admissionNums") List<String> admissionNums);

    Task getStudentMarkTask(@Param("projectId") String projectId, @Param("subjectId") String subjectId, @Param("admissionNum") String admissionNum);

    /**
     * 硬删除评卷任务
     *
     * @param needRemoveTaskIdList
     * @return 影响条数
     */
    int removeTask(@Param("needRemoveTaskIdList") List<String> needRemoveTaskIdList);

    /**
     * 查询需要删除的评卷任务id
     *
     * @param projectId     评卷项目id
     * @param admissionNums 准考证号
     * @return 需要删除的评卷任务id
     */
    List<String> getNeedRemoveTask(@Param("projectId") String projectId, List<String> admissionNums);


    /**
     * 查询任务部分id
     *
     * @param projectId
     * @return
     */
    List<Task> queryTask(@Param("projectId") String projectId);


    /**
     * 查询专家未评卷任务
     *
     * @param examExpertSettingParam
     * @return
     */
    List<Task> queryTaskPieceScore(ExamExpertSettingParam examExpertSettingParam);


    /**
     * 查询未评卷任务
     *
     * @param examExpertSettingParam
     * @return
     */
    List<Task> queryTaskByExamExpertSetting(ExamExpertSettingParam examExpertSettingParam);


    /**
     * 查询已分配给专家且未评卷打分记录
     *
     * @param projectId
     * @return
     */
    List<TaskPieceScoreVo> queryPieceScoreTask(@Param("projectId") String projectId);


    /**
     * 已评完的打分记录
     * @param projectId
     * @return
     */
    List<TaskPieceScoreVo> queryAlreadyPieceScoreTask(@Param("projectId") String projectId);

    /**
     * 查询专家已分配评卷任务数
     *
     * @param projectId
     * @return
     */
    List<TaskNumberVo> queryTaskNumberVo(@Param("projectId") String projectId);


    /**
     * 查询专家已完成的评卷任务数
     * @param projectId
     * @return
     */
    List<TaskNumberVo> queryFinishTaskPieceScore(@Param("projectId") String projectId);

    /**
     * 根据评卷块得分获取评卷任务
     *
     * @param pieceScoreId
     * @return
     */
    Task selectTaskByPieceScore(@Param("pieceScoreId") String pieceScoreId, @Param("userId") String userId);

    Task selectTaskByTaskId(@Param("taskId") String taskId);

    /**
     * 更新考试下所有的考试状态为已评卷
     *
     * @param projectId
     * @param subjectId
     * @return
     */
    int updateAllStudentStatus(@Param("projectId") String projectId, @Param("subjectId") String subjectId);

    /**
     * 更新考试下所有的考试状态为已评卷
     *
     * @param pieceScores
     * @param
     * @return
     */
    int updateAllStudentStatusByIds(@Param("pieceScores") List<PieceScore> pieceScores);


    /**
     * 更新考试下所有的考试状态为评卷中
     *
     * @param
     * @param taskId
     * @return
     */
    int updateStudentStatusRunningById(@Param("taskId") String taskId);



    /**
     * @param currUserId
     * @param projectId
     * @param subjectId
     * @return
     */
    Integer countSubjectFinishStatus(
    		@Param("currUserId") String currUserId,
    		@Param("projectId") String projectId,
    		@Param("subjectId") String subjectId,
    		@Param("finishStatus") int finishStatus);
    
    /**
     * @param projectId
     * @param encodeId
     * @return
     */
    Integer countSubjectUnFinishStatus(
    		@Param("projectId") String projectId,
    		@Param("encodeId") String encodeId,
    		@Param("finishStatus") Integer finishStatus);

    /**
     * @param currUserId
     * @param projectId
     * @param subjectId
     * @return
     */
    Integer countBatchFinishStatus(
    		@Param("currUserId") String currUserId,
    		@Param("projectId") String projectId,
    		@Param("subjectId") String subjectId,
    		@Param("batchId") String batchId,
    		@Param("finishStatus") int finishStatus);

    /**
     * @param currUserId
     * @param projectId
     * @param subjectId
     * @param batchId
     * @return
     */
    Integer countAllStatus(
    		@Param("currUserId") String currUserId,
    		@Param("projectId") String projectId,
    		@Param("subjectId") String subjectId,
    		@Param("batchId") String batchId,
    		@Param("placeId") String placeId,
    		@Param("roomId") String roomId);

    /**
     * 获取老师下的所有的评卷数量
     *
     * @param currUserId
     * @param projectId
     * @param subjectId
     * @return
     */
    Integer countSubjectAllStatus(
    		@Param("currUserId") String currUserId,
    		@Param("projectId") String projectId,
    		@Param("subjectId") String subjectId);

    /**
     * 获取老师下的所有的评卷数量
     *
     * @param currUserId
     * @param projectId
     * @param subjectId
     * @return
     */
    Integer countBatchAllStatus(
    		@Param("currUserId") String currUserId,
    		@Param("projectId") String projectId,
    		@Param("subjectId") String subjectId,
    		@Param("batchId") String batchId);


    Integer countAllFinishStatus(
    		@Param("currUserId") String currUserId,
    		@Param("projectId") String projectId,
    		@Param("subjectId") String subjectId,
    		@Param("batchId") String batchId,
    		@Param("placeId") String placeId,
    		@Param("roomId") String roomId,
    		@Param("finishStatus") int finishStatus);

    /**
     * 获取考试下已经考完的考生task
     * @param projectId
     * @param subjectId
     * @param currUserId
     * @return
     */
    List<TaskVo> getFinishTaskVoList(
    		@Param("projectId") String projectId,
    		@Param("subjectId") String subjectId,
    		@Param("currUserId") String currUserId,
    		@Param("batchId") String batchId,
    		@Param("placeId") String placeId,
    		@Param("roomId") String roomId
    		);


    /**
     * 获取考试下已经考完的考生task
     * @param projectId
     * @param
     * @param currUserId
     * @return
     */
    TaskVo getFinishTaskVo(
    		@Param("taskId") String projectId,
    		@Param("currUserId") String currUserId);




    /**
     * 获取当前考试下的所以考生
     * @param projectId
     * @param subjectId
     * @param currUserId
     * @return
     */
    List<TaskVo> selectFinishTask(@Param("projectId") String projectId,@Param("subjectId") String subjectId,@Param("currUserId") String currUserId);

    /**
     * 更新tasklist中的数据为已完成
     * @param pushTaskVoList
     * @return
     */
    int updateTaskListStatus(@Param("pushTaskVoList") List<TaskVo> pushTaskVoList);

    /**
     * 获取考点下的考场
     * @param projectId
     * @param palceId
     * @return
     */
    List<OptionItemVo> getExpertRoom(String projectId, String palceId);


    List<Task> queryTaskGroupByMarkModel(@Param("projectId") String projectId);


    /**
     * 查询任务id
     * @param projectId
     * @param batchId
     * @param roomId
     * @return
     */
    List<Task> getTaskSubjects(@Param("projectId")  String projectId,@Param("batchId")  String batchId,  @Param("roomId") String roomId);

    int updateTaskMarkStatusByIds(@Param("taskIds") List<String> taskIds);
}
